<?php
class Timer {
	const GLOBAL_EVENT	= '__GLOBAL';
	private $_events = NULL;
	
	public function __construct() {
		$this->_events = array();
	}

	private function getTime() {
	    list ($msec, $sec) = explode(' ', microtime());
	    $microtime = (float)$msec + (float)$sec;
	    return $microtime;
	}

	public function start($eventName = self::GLOBAL_EVENT) {
		return ($this->_events[$eventName] = $this->getTime());
	}

	public function getPeriod($eventName = self::GLOBAL_EVENT) {
		if (isset($this->_events[$eventName])) {
			return $this->getTime() - $this->_events[$eventName];
		} else {
			return NULL;
		}
	}	
}
